//
//  CategoryCell.swift
//  ChinaLandMark
//
//  Created by Felix Hi on 2021/6/29.
//

import SwiftUI

struct CategoryCell: View {
    let categoryName: String
    let landmarks: [Landmark]
    
    var body: some View {
        VStack (alignment: .leading) {
            Text(categoryName)
                .font(.headline)
            ScrollView (.horizontal, showsIndicators: false) {
                HStack (spacing: 20) {
                    ForEach (landmarks) { landmark in
                        // 每个景点item
                        NavigationLink (destination: LandMarkDetail(landmark: landmark)) {
                            VStack {
                                Image(systemName: landmark.imageName)
                                    .renderingMode(.original)
                                    .resizable()
                                    .frame(width: 155, height: 155)
                                Text(landmark.name)
                                    .font(.caption)
                                    .foregroundColor(.primary)
                            }
                        }
                    }
                }
            }
        }
        .padding([.leading, .trailing], 15)
        .padding([.top, .bottom], 15)
    }
}

struct CategoryCell_Previews: PreviewProvider {
    static var previews: some View {
        CategoryCell(categoryName: landmarks[0].category, landmarks: Array(landmarks.prefix(4)))
    }
}
